<%--
  Created by IntelliJ IDEA.
  User: Z-7
  Date: 2022/3/4
  Time: 16:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="${pageContext.request.contextPath}/resource/bootstrap4/css/bootstrap.css" rel="stylesheet">
    <script type="text/javascript" src="${pageContext.request.contextPath}/resource/js/jquery-3.2.1.js"></script>
    <script type="text/javascript"
            src="${pageContext.request.contextPath}/resource/bootstrap-treeview/js/bootstrap-treeview.js"></script>
    <script src="${pageContext.request.contextPath}/resource/bootstrap4/js/bootstrap.js"></script>
    <title>注册</title>
</head>
<body>
<blockquote class="blockquote text-center">
    <p class="mb-0">支付宝基金</p>
    <footer class="blockquote-footer">欢迎<cite title="Source Title">您</cite></footer>
</blockquote>
<div class="container">
    <form action="${pageContext.request.contextPath}/user/register" method="post">
        <div class="form-group">
            <label for="exampleInputEmail1">手机号</label>
            <input type="text" class="form-control" id="exampleInputEmail1" onblur="uniquePhone(this.value)" name="username"><button type="button" class="btn btn-primary" onclick="getCode()">获取验证码</button>
            <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
        </div>
        <div class="form-group">
            <label for="exampleInput2">验证码</label>
            <input type="text" class="form-control" id="exampleInput2" name="code">
        </div>
        <div class="form-group">
            <label for="exampleInputPassword1" id="p1">密码</label>
            <input type="password" class="form-control" onblur="pwd1(this.value)" name="pwd" id="exampleInputPassword1">
        </div>
        <div class="form-group">
            <label for="exampleInputPassword2" id="p2">重复密码</label>
            <input type="password" class="form-control" onblur="re_pwd1(this.value)" name="re_pwd" id="exampleInputPassword2">
        </div>
        <div class="alert alert-primary" role="alert">
            <button type="submit" id="tj" class="btn btn-primary">注册</button>
            去<a href="${pageContext.request.contextPath}/user/login" class="alert-link">登录</a>
            <span style="color: red">${error}</span>
        </div>
    </form>
</div>
<script type="text/javascript">
    function getCode() {
        $.post("/user/getCode",{"phone":$("[name='username']").val()},function (str){})
    }
    function pwd1(pwd) {
        if(pwd == ""){
            alert("请输入密码");
            $("#tj").prop("disabled",true);
        }else {
            $("#tj").prop("disabled",false);
        }
        if($('[name="re_pwd"]').val() != ""){
            if(pwd == $('[name="re_pwd"]').val()){
                $("#tj").prop("disabled",false);
                $("span").html("");
                return;
            }
            $("span").html("两次密码不一致");
            $("#tj").prop("disabled",true);
        }
    }
    function re_pwd1(pwd) {
        if(pwd == ""){
            alert("请再次输入密码");
            $("#tj").prop("disabled",true);
        }else {
            $("#tj").prop("disabled",false);
        }
        if($('[name="pwd"]').val() != ""){
            if(pwd == $('[name="pwd"]').val()){
                $("#tj").prop("disabled",false);
                $("span").html("");
                return;
            }
            $("span").html("两次密码不一致");
            $("#tj").prop("disabled",true);
        }
    }
    function uniquePhone(phone) {
        $.post("${pageContext.request.contextPath}/user/uniquePhone",{"phone":phone},function (flag) {
            if(flag){
                $("#tj").prop("disabled",false);
                $("span").html("");
            }else{
                $("span").html("手机号已存在");
                $("#tj").prop("disabled",true);
            }
        })
    }
</script>
</body>
</html>
